//-----------------------------------整点秒杀倒计时-------------------------------------------------
var now = new Date();
		var futrue = new Date("2020-11-11")
		var cc = Math.abs(now.getTime() - futrue.getTime()) / 1000
		var intDiff = parseInt(cc); //倒计时总秒数量
		function timer(intDiff) {
			window.setInterval(function() {
				var day = 0,
					hour = 0,
					minute = 0,
					second = 0; //时间默认值        
				if (intDiff > 0) {
					day = Math.floor(intDiff / (60 * 60 * 24));
					hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
					minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
					second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
				}
				if (minute <= 9) minute = '0' + minute;
				if (second <= 9) second = '0' + second;
				$('#day_show').html(day + "天");
				$('#hour_show').html('<s id="h"></s>' + hour + '时');
				$('#minute_show').html('<s></s>' + minute + '分');
				$('#second_show').html('<s></s>' + second + '秒');
				intDiff--;
			}, 1000);
		}
		$(function() {
			timer(intDiff);
		});
//---------------------------请求数据渲染页面并且实现分页的功能---------------------------------------------------
// 从后端加载来的所有数据;
var res_goods  = null;
// 每页显示的数量
var show_count = 40;
//当前显示页码
var page = 0;


// 发送ajax请求数据并接收数据
$.ajax("http://localhost:3000/pxx",{
	data:{
		page:1,
		size:400
	}
})
.then(function(res){
	  //引入分页器插件，并向render函数中传参
		$('#box').paging({
		initPageNo: 1, // 初始页码
		totalPages: 10, //总页数
		
		slideSpeed: 600, // 缓动速度。单位毫秒 
		callback: function(page) { // 回调函数，page为当前显示页码
		   render(res,page); 
		}
	})
	
	
})
//-------------------------根据不同的页码向页面中渲染不同的数据完成动态渲染和分页的功能-------------------------------------------
function render(res,page){
	var html=''
	res_goods =  res.goods;
	for(var i=show_count * page ; i<=show_count * page + (show_count-1) ; i++){
		var b =`<div class="goods">
					<img src=${res_goods[i].hd_thumb_url} alt="" class="img img-thumbnail">
					<div class="qrcode">
					<img src="//cdn.pinduoduo.com/home/static/img/qrcode/natural/qrcode.png" alt="" class="img ">
					<div class="qrcode-text">微信扫我购买</div>
					</div>
					<div class="title">${res_goods[i].goods_name}</div>
					<div class="price">
					  "￥"
					  <span class="group-price">${res_goods[i].normal_price/100}</span>
					  <span class="market-price">￥${res_goods[i].market_price/100}</span>
					  <span class="count">
						  ${res_goods[i].sales_tip}
					  </span>
					</div>
				</div>`
		html+=b;
	}
	
	$(".goods-group").html(html);
}


